package cn.singno.springBoot.demo.ch08_event;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main
{
	private AnnotationConfigApplicationContext context = null;
	private DemoPulisher demoPulisher = null;
	private DemoPulisher2 demoPulisher2 = null;
	
	@Before
	public void before() throws Exception
        {
		context = new AnnotationConfigApplicationContext(EventConfig.class);
		demoPulisher = context.getBean(DemoPulisher.class);
		demoPulisher2 = context.getBean(DemoPulisher2.class);
        }
	
	@After
	public void after() throws Exception
        {
		context.close();
        }
	
	@Test
	public void test1() throws Exception
        {
		int num = 10;
		for (int i = 0; i < num; i++)
                {
			System.out.println("执行test1-start：" + i);
			demoPulisher.publish("hello application event：" + i);
			System.out.println("执行test1-end：" + i);
                }
        }
	
	@Test
	public void test2() throws Exception
        {
		int num = 10;
		for (int i = 0; i < num; i++)
                {
			System.out.println("执行test1-start：" + i);
			demoPulisher2.publish("hello application event：" + i);
			System.out.println("执行test1-end：" + i);
                }
        }
}
